<template>
    <view>
        <view class="my_refresh">
            <view class="mpi" v-if="ifshow == 1">
                <view class="section">
                    <view class="div">
                        <view class="lovebname">当前排名</view>
                        <text class="font">第</text>
                        <text class="span" :style="'color:' + color + ';'">{{ mc }}</text>
                        <text class="font">名</text>
                    </view>
                    <view class="div">
                        <view class="lovebname">当前{{ lovebname }}</view>
                        <text class="span" :style="'color:' + color + ';'">{{ loveb }}</text>
                        <text class="font">个</text>
                    </view>
                </view>
                <view class="Clist">
                    <block v-if="price > 0">
                        <view class="div">
                            1．刷新靠前一次需花费
                            <text class="i ico" :style="'color:' + color + ';'"></text>
                            <text class="font" :style="'color:' + color + ';'">{{ price }}</text>
                            {{ lovebname }}，直到其他会员将你顶下去，否则你将永远排前面
                        </view>
                        <view class="div">2．请不要频繁连续申请，申请一次扣除一次，推荐两天刷新一次，土豪随意</view>
                    </block>
                    <block v-else>
                        <view class="div">1．申请刷新后，直到其他会员将你顶下去，否则你将永远排前面</view>
                        <view class="div">2．请不要频繁连续申请，推荐两天刷新一次</view>
                    </block>
                </view>
            </view>
            <view class="mpi" v-else>
                <view class="i ico sorrympi"></view>
                <view class="h3">您无法使用此功能</view>
                <view class="tipstr">
                    <view>1．头像未上传</view>
                    <view>2．资料不完善</view>
                    <view>（例如：生日、身高、学历，职业等）</view>
                </view>
                <text @tap="moddataFn" class="btn3" :style="'background-color:' + color">
                    <text class="ico"></text>
                    我要完善资料
                </text>
                　
                <text @tap="moddataFn" class="btn3" :style="'background-color:' + color">
                    <text class="ico"></text>
                    我要上传头像
                </text>
            </view>
            <view class="mpi">
                <view class="linebox">
                    <view class="line W50"></view>
                    <view class="title BAI">会员排名TOP10</view>
                </view>
                <view class="topbar" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor">
                    <text @tap="topbarFn" :class="'item ' + (currentTab == index ? 'active' : '')" :data-idx="index" v-for="(item, index) in topbar" :key="index">{{ item }}</text>
                </view>
                <view class="dl tbody">
                    <view class="dt">名次</view>
                    <view class="dd">会员</view>
                </view>
                <view class="my_refresh_list">
                    <block v-if="currentTab == 0">
                        <view class="dl" v-for="(item, idx) in LIST1" :key="idx">
                            <view class="dt">
                                第
                                <text class="font">{{ idx + 1 }}</text>
                                名
                            </view>

                            <view class="dd">
                                <image class="ugrade1" :src="item.grade_ico"></image>
                                {{ item.nickname }}
                                <text class="own" v-if="item.class != ''">(我)</text>
                            </view>
                        </view>
                    </block>
                    <block v-if="currentTab == 1">
                        <view class="dl" v-for="(item, idx) in LIST2" :key="idx">
                            <view class="dt">
                                第
                                <text class="font">{{ idx + 1 }}</text>
                                名
                            </view>

                            <view class="dd">
                                <image class="ugrade1" :src="item.grade_ico"></image>
                                {{ item.nickname }}
                                <text class="own" v-if="item.class != ''">(我)</text>
                            </view>
                        </view>
                    </block>
                    <block v-if="currentTab == 2">
                        <view class="dl" v-for="(item, idx) in LIST3" :key="idx">
                            <view class="dt">
                                第
                                <text class="font">{{ idx + 1 }}</text>
                                名
                            </view>

                            <view class="dd">
                                <image class="ugrade1" :src="item.grade_ico"></image>
                                {{ item.nickname }}
                                <text class="own" v-if="item.class != ''">(我)</text>
                            </view>
                        </view>
                    </block>
                </view>
            </view>
        </view>
        <view class="my_mateshow_btm" :style="'--color:' + color + ';--rgbcolor:' + rgbcolor">
            <view @tap="btnFn" class="btn5">
                <text class="i ico"></text>
                立即刷新靠前
            </view>
        </view>
    </view>
</template>

<script>
var o = require('../../res/www.a9a.cn.js');
var app = getApp();
var e = uni.getStorageSync('COOK_U');
export default {
    data() {
        return {
            topbar: ['全部', '男生', '女生'],
            currentTab: 0,
            color: '',
            rgbcolor: '',
            lovebname: '',
            ifshow: '',
            mc: '',
            loveb: '',
            price: '',
            LIST1: '',
            LIST2: '',
            LIST3: ''
        };
    },
    onLoad: function () {
        var that = this;
        app.globalData.get_config('_ZEAI').then(function (t) {
            that.setData({
                color: t.color,
                rgbcolor: o.c16_rgb(t.color),
                lovebname: t.loveb
            });
        });
        app.globalData.chklogin().then(function (o) {
            if (o) {
                app.globalData.get_openid().then(function (o) {
                    app.globalData.ajax({
                        url: 'my_refresh.php',
                        data: {
                            submitok: 'init',
                            openid: o
                        },
                        success: function (o) {
                            if (1 == o.flag) {
                                that.setData({
                                    ifshow: o.ifshow,
                                    mc: o.mc,
                                    loveb: o.loveb,
                                    price: o.price,
                                    LIST1: o.ARR1,
                                    LIST2: o.ARR2,
                                    LIST3: o.ARR3
                                });
                            } else {
                                if ('noreg' == o.flag) {
                                    uni.redirectTo({
                                        url: '/pages/login/login'
                                    });
                                } else {
                                    uni.showToast({
                                        title: o.msg,
                                        icon: 'none',
                                        mask: true
                                    });
                                }
                            }
                        }
                    });
                });
            } else {
                uni.showModal({
                    content: '亲~~~请先登录完善资料再来申请哦',
                    confirmColor: that.color,
                    confirmText: '朕知道了',
                    showCancel: false,
                    success: function (o) {
                        uni.redirectTo({
                            url: '/pages/login/login'
                        });
                    }
                });
            }
        });
    },
    methods: {
        topbarFn: function (o) {
            var t = parseInt(o.currentTarget.dataset.idx);
            this.setData({
                currentTab: t
            });
        },

        moddataFn: function () {
            uni.navigateTo({
                url: '/pagesA/reg/reg'
            });
        },

        btnFn: function () {
            1 == this.ifshow
                ? this.price > 0
                    ? uni.showModal({
                          content: '确定提交么？\n刷新靠前一次需花费' + this.price + this.lovebname,
                          confirmColor: this.color,
                          cancelText: '取消',
                          confirmText: '确定',
                          success: function (o) {
                              if (o.confirm) {
                                  app.globalData.ajax({
                                      url: 'my_refresh.php',
                                      data: {
                                          submitok: 'ajax_modupdate',
                                          openid: e.openid
                                      },
                                      success: function (o) {
                                          1 == o.flag
                                              ? (uni.showToast({
                                                    title: o.msg,
                                                    icon: 'none',
                                                    mask: true
                                                }),
                                                setTimeout(function () {
                                                    uni.redirectTo({
                                                        url: 'refresh'
                                                    });
                                                }, 2000))
                                              : uni.showToast({
                                                    title: o.msg,
                                                    duration: 4000,
                                                    icon: 'none',
                                                    mask: true
                                                });
                                      }
                                  });
                              }
                          }
                      })
                    : app.globalData.ajax({
                          url: 'my_refresh.php',
                          data: {
                              submitok: 'ajax_modupdate',
                              openid: e.openid
                          },
                          success: function (o) {
                              1 == o.flag
                                  ? (uni.showToast({
                                        title: o.msg,
                                        icon: 'none',
                                        mask: true
                                    }),
                                    setTimeout(function () {
                                        uni.redirectTo({
                                            url: 'refresh'
                                        });
                                    }, 2000))
                                  : uni.showToast({
                                        title: o.msg,
                                        duration: 4000,
                                        icon: 'none',
                                        mask: true
                                    });
                          }
                      })
                : uni.showModal({
                      content: '您无法使用此功能\n1．头像未上传\n2．资料不完善',
                      confirmColor: this.color,
                      confirmText: '朕知道了',
                      showCancel: false,
                      success: function (o) {}
                  });
        }
    }
};
</script>
<style>
@import 'refresh.css';
</style>
